package com.cros.jasper;

import java.io.File;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.sf.jasperreports.engine.JRException; 
import net.sf.jasperreports.engine.JasperReport; 
//import net.sf.jasperreports.engine.design.JasperDesign; 
import net.sf.jasperreports.engine.util.JRLoader; 
import net.sf.jasperreports.engine.xml.JRXmlWriter; 

/*
 * Este clase ocupa el jar jasperreports-3.5.0.jar
 * */
class JasperJrxml { 
	
	private static Log log = LogFactory.getLog(JasperJrxml.class);

    private String sourcePath;
    private String destinationPath;
    
    public JasperJrxml(String sourcePath,String destinationPath){
    	this.sourcePath=sourcePath;
    	this.destinationPath=destinationPath;  	
    }
    
    public JasperJrxml(){
    	sourcePath="C:/Report_Aseval_Web_Afiliados/probandoJasperTojrcml.jasper";
        destinationPath="C:/Report_Aseval_Web_Afiliados/vuala.jrxml";	
    }

    public void convertJasperToJrxml() throws JRException{
    	try{ 
    		File fichero = new File(sourcePath);
    		if(fichero.exists()){
    			JasperReport report = (JasperReport) JRLoader.loadObject(sourcePath); 
    			JRXmlWriter.writeReport(report,destinationPath, "ISO-8859-1");
    		}else{
    			log.info("The sourcePath:"+sourcePath+" doesn't exist.");
    		}
          } catch (JRException e) {
          	log.error("",e);
          	throw e;
          } 
    }
    
    public static void main(String []argv) throws JRException{
    	JasperJrxml jrm = new JasperJrxml();
    	jrm.convertJasperToJrxml();
    }
	public void setSourcePath(String sourcePath) {
		this.sourcePath = sourcePath;
	}

	public String getSourcePath() {
		return sourcePath;
	}

	public void setDestinationPath(String destinationPath) {
		this.destinationPath = destinationPath;
	}

	public String getDestinationPath() {
		return destinationPath;
	} 

}